_=document||window.document;
log=console.log||window.console.log||null;
window.requestAnimationFrame = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.msRequestAnimationFrame;
function lsg(key) {
    return localStorage.getItem(key);
}
function lss(key,value) {
    return localStorage.setItem(key,value);
}
$.fn.mst=function (str) {
    function reckonVal(pro) {
        pro.substr(-1)!=="%"&pro.substr(-2)!=="px"&&(pro=pro+"px");
        return pro;
    }
    if(str===undefined){
        return this;
    }

    //str.substr(-1)===";"&&(str=str.substr(0,str.length-1-2));


    str=str.split(";");
    for(var x in str){
        if(str.hasOwnProperty(x)){
            var c=str[x].substr(1);
            var d=str[x].substr(2);
            var e=str[x].substr(3);
            switch (str[x]){
                case "fl":
                    this.css("float","left");
                    continue;
                case "fr":
                    this.css("float","right");
                    continue;
                case "ofh":
                    this.css("overflow","hidden");
                    continue;
                case "bpc":
                    this.css("background-position","center");
                    continue;
                case "poa":
                    this.css("position","absolute");
                    continue;
                case "pof":
                    this.css("position","fixed");
                    continue;
                case "por":
                    this.css("position","relative");
                    continue;
                case "dib":
                    this.css("display","inline-block");
                    continue;
                case "dpb":
                    this.css("display","block");
                    continue;
                case "dpn":
                    this.css("display","none");
                    continue;
                case "cup":
                    this.css("cursor","pointer");
                    continue;
                case "m0a":
                    this.css({
                        "margin-top":"0",
                        "margin-bottom":"0",
                        "margin-left":"auto",
                        "margin-right":"auto"
                    });
                    continue;
                case "bgrn":
                    this.css("background-repeat","no-repeat");
                    continue;
            }
            switch (str[x].substr(0,3)){
                case "bgp":
                    this.css("background-position",e);
                    continue;
                case "tac":
                    this.css("text-align","center");
                    continue;
                case "tar":
                    this.css("text-align","right");
                    continue;
                case "bgi":
                    this.css("background-image",e);
                    continue;
                case "bgc":
                    this.css("background-color",e);
                    continue;
                case "bgs":
                    this.css("background-size",e);
                    continue;
                case "bdr":
                    this.css("border-radius",reckonVal(e));
                    continue;
                case "maw":
                    this.css("max-width",reckonVal(e));
                    continue;
                case "mah":
                    this.css("max-height",reckonVal(e));
                    continue;
                case "miw":
                    this.css("min-width",reckonVal(e));
                    continue;
                case "mih":
                    this.css("min-height",reckonVal(e));
                    continue;
            }
            switch (str[x].substr(0,2)){
                case "op":
                    this.css("opacity",d);
                    continue;
                case "ls":
                    this.css("letter-space",d+"px");
                    continue;
                case "tr":
                    this.css("transition",d+"ms");
                    continue;
                case "lh":
                    this.css("line-height",reckonVal(d));
                    continue;
                case "bd":
                    this.css("border",d);
                    continue;
                case "bg":
                    this.css("background",d);
                    continue;
                case "fz":
                    this.css("font-size",d);
                    continue;
                case "mt":
                    this.css("margin-top",reckonVal(d));
                    continue;
                case "mb":
                    this.css("margin-bottom",reckonVal(d));
                    continue;
                case "ml":
                    this.css("margin-left",reckonVal(d));
                    continue;
                case "mr":
                    this.css("margin-right",reckonVal(d));
                    continue;
                case "pt":
                    this.css("padding-top",reckonVal(d));
                    continue;
                case "pb":
                    this.css("padding-bottom",reckonVal(d));
                    continue;
                case "pl":
                    this.css("padding-left",reckonVal(d));
                    continue;
                case "pr":
                    this.css("padding-right",reckonVal(d));
                    continue;
            }
            switch (str[x].substr(0,1)){
                case "w":
                    this.css("width",reckonVal(c));
                    continue;
                case "h":
                    this.css("height",reckonVal(c));
                    continue;
                case "t":
                    this.css("top",reckonVal(c));
                    continue;
                case "b":
                    this.css("bottom",reckonVal(c));
                    continue;
                case "l":
                    this.css("left",reckonVal(c));
                    continue;
                case "r":
                    this.css("right",reckonVal(c));
                    continue;
                case "m":
                    this.css("margin",reckonVal(c));
                    continue;
                case "c":
                    this.css("color",c);
                    continue;
                case "p":
                    this.css("padding",reckonVal(c));
                    continue;
                default:
                    log(this);
                    log("该对象引用mst方法时,参数 \""+str[x]+"\" 不能被识别");
            }
        }
    }
    return this;
};
var tag={
    a:function () {
        return $("<a></a>").css("display","inline-block");
    },
    div:function () {
        if(arguments[0]!==undefined){
            return $("<div></div>").mst(arguments[0]);
        }
        return $("<div></div>");
    },
    input:function input(type,value) {
        return $("<input type='"+type+"' value='"+value+"'>");
    },
    span:function () {
        return $("<span></span>").mst("dib");
    },
    canvas:function () {
        return $("<canvas></canvas>");
    },
    script:function (src) {
        return $("<script src='"+src+"'></script>");
    },
    ul:function () {
        return $("<ul></ul>");
    },
    ol:function () {
        return $("<ol></ol>")
    },
    li:function () {
        return $("<li></li>")
    }
};
function buble(msg,w,h) {
    var c=tag.canvas().attr({
        "width":w+2,
        "height":11
    }).mst("dpb");
    var o=c[0].getContext("2d");
    o.beginPath();
    o.moveTo(0,11);
    o.lineTo(w/2-7,11);
    o.lineTo(w/2,3);
    o.lineTo(w/2+7,11);
    o.lineTo(w+2,11);
    o.strokeStyle="#666";
    o.lineWidth=2;
    o.stroke();
    o.fillStyle="#fff";
    o.fill();
    var box=tag.div().mst("w"+(w-8)+";h"+(h-8)+";bg#fff;p4").html(msg).css({
        "border-left":"1px solid #666",
        "border-right":"1px solid #666",
        "border-bottom":"1px solid #666"
    });
    return tag.div().append(c,box).mst("dib");
}
function myAjax(method,url,data,succ){
    data=data||"";
    method=method||"get";
    var xhr=new XMLHttpRequest();
    xhr.open(method,url);
    if(method.toLowerCase()==="post"){
        xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    }
    xhr.send(data);
    xhr.onreadystatechange=function () {
        if(xhr.readyState===4&&xhr.status===200){
            succ(xhr.responseText);
        }
    }
}
function loadJs(src){
    var tag=_.createElement("script");
    tag.src=src;
    _.head.appendChild(tag);
}




//房子-房间-窗户模型 内容-可视区-进度条控制-鼠标滚轮控制
function House(room, windows) {
    var view=true;
    function fixPro(percent) {
        pro.css("top",percent*(windows.height()-pro.height())+"px");
    }
    var pro = tag.div().mst("poa;t0;bgrgba(0,0,0,0.3);w10;r0;cud");
    windows.append(room, pro).mst("por;ofh");
    var room_top,pro_top, pro_y_changed, pro_md_y, pro_height, per, room_max_top, room_overflow_height;
    windows.bind
    ({
        "mouseover": function ()
        {
            if(!view){
                return;
            }
            windowMWD = function ()
            {
                room_top = room[0].offsetTop;
                if (room_top <= -(room.height() - windows.height()))
                {
                    room.css("top", -(room.height() - windows.height()) + "px");
                } else {
                    room.css("top", room_top - 100 + "px");
                }

                per = room[0].offsetTop/-(room.height()-windows.height());
                per <= 0 && (per = 0);
                fixPro(per);
            };
            windowMWU = function () {
                room_top = room[0].offsetTop;
                if (room_top >= 0) {
                    room.css("top", "0px");
                } else {
                    room.css("top", room_top + 100 + "px");
                }
                per = -room[0].offsetTop/(room.height()-windows.height());
                per > 1 && (per = 1);
                fixPro(per);
            };
        },
        "mouseout": function () {
            windowMWD = null;
            windowMWU = null;
        }
    });
    pro.bind
    ({
        "mousedown": function (e) {
            //pt=pro.top();
            pro_md_y = e.pageY;
            pro_top = pro[0].offsetTop;
            pro_height = pro.height();
            room_overflow_height = room.height() - windows.height();
            room_max_top = 550 - pro_height;
            windowMovePara = mouseMoveFun;
        }
    });
    var mouseMoveFun = function (x, y)
    {
        pro_y_changed = y - pro_md_y;
        x = pro_top + pro_y_changed;
        if (x <= 0)
        {
            x = 0;
        }
        else if (x >= room_max_top)
        {
            x = room_max_top;
        }
        per = (x / room_max_top).toFixed(2);
        pro.css("top", x + "px");
        room.css("top", -per * room_overflow_height + "px");
    };
    House.prototype.fix = function ()
    {
        var per = windows.height() / room.height();
        if(per>1){
            view=false;
            pro.mst("dpn");
        }
        pro.css("height", per * windows.height() + "px");
    }

}
/*window.$=po (selector)
{
  return new $.po.init(selector);
};
$.po=$.prototype=
    {
        init:po (argument)
        {
            switch (typeof argument)
            {
                case "object":this[0]=argument;break;
                case "po":return window.addEventListener("load",argument);
                case "string":switch (argument.substr(0,1))
                {
                    case ".":this[0]=_.getElementsByClassName(argument.substr(1))[0];break;
                    case "#":this[0]=_.getElementById(argument.substr(1));break;
                    default:this[0]=_.getElementsByTagName(argument.substr(1));
                }
            }
            return this;
        },
        html:po (str) {
            if(str){
                this[0].innerHTML=str;
                return this;
            }else {
                return this[0].innerHTML;
            }
        },
        width:po (int) {
            if(int){
                this[0].width=int;
                return this;
            }else {
                return this[0].width;
            }
        }
};
$.po.init.prototype=$.po;*/

/*log=po (str)
{
    if(!this.win)
    {
        this.win=$("<div></div>").css
        ({
            "position": "fixed",
            "bottom": "0",
            "color":"#f00",
            "text-shadow":"1px 1px 2px #fff",
            "font-width":"100"
        });
        $("body").append(this.win);
    }
    var date=new Date();
    this.win.append(date.getHours()+":"+date.getMinutes()+":"+date.getSeconds()+":&nbsp;"+str+"<br>");
};*/

//封装XMLHttpRequest以及跨域获取json技术 使用方法：不告诉你
function ajax(json) {
    //数据
    var data=json.data;
    //目标地址
    var url=json.url;
    //请求方式 默认get 顺便大写处理了
    var method=json.method;
    if(!method)
    {
        method="GET"
    }
    method=method.toLocaleUpperCase();
    //是否为跨域请求 默认否
    var isCrossDomain=json.cross_domain;
    //是否为异步请求 默认是 sync是同步的意思 async才是异步的意思
    var sync=json.sync;
    //ajax请求成功执行的函数
    var success=json.success;
    //数据字符串
    var dataStr="";
    //合成数据字符串
    for(var key in data)
    {
        if(data.hasOwnProperty(key))
        {
            dataStr=dataStr+"&"+key+"="+data[key]
        }
    }
    //验证、处理数据字符串
    if(dataStr!=="")
    {
        dataStr=dataStr.substr(1)
    }
    //判断是否跨域  处理跨域请求 jsonp 合成地址 包括请求数据
    //跨域请求需要自定义回调函数
    if(isCrossDomain)
    {
        url=url+"?"+dataStr;
        //生成标签 不解释
        _.script=_.createElement("script");
        _.script.setAttribute("src",url);
        var head=$("head")[0];
        head.appendChild(_.script)
    }
    //处理站内请求 ajax
    else
    {
        var xhr;
        if (XMLHttpRequest)
        {
            xhr=new XMLHttpRequest()

        }
        //为了兼容IE小儿子 勉为其难的写下else
        else
        {
            xhr=new ActiveXObject("Microsoft.XMLHTTP")
        }
        //异步请求状态监控
        if(!sync)
        {
            xhr.onreadystatechange=function ()
            {
                //log("readyState:"+xhr.readyState+" \r\n____status:"+xhr.status);
                //接收到数据执行success方法
                if(xhr.readyState===4&&xhr.status===200)
                {
                    success(xhr.responseText)
                }
            }
        }
        //发送请求和数据
        if(method="GET")
        {
            xhr.open(method,url,!sync);
            xhr.send(dataStr)
        }
        else if(method="POST")
        {
            xhr.open(method,url,!sync);
            //post请求必须包含请求头 get则不必
            xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
            xhr.send(dataStr)
        }
        //同步请求执行 不推荐使用同步
        if(sync)
        {
            win.xhrResTxt=success(xhr.responseText)
        }
    }
}